use anyhow::Result;
use crate::models::state::{CallRecord, CallStatus, CallType};
use crate::repositories::call_repository::CallRepository;

pub struct CallService;

impl CallService {
    pub fn new_outgoing_record(target: &str) -> CallRecord {
        CallRecord { id: format!("call_{}", chrono::Utc::now().timestamp_millis()), target: target.to_string(), target_display: target.to_string(), call_type: CallType::Outgoing, status: CallStatus::Cancelled, timestamp: chrono::Utc::now().timestamp_millis(), duration: None }
    }
    pub async fn get_history() -> Result<Vec<CallRecord>> { CallRepository::list().await }
    pub async fn search_history(query: &str) -> Result<Vec<CallRecord>> { CallRepository::search(query).await }
    pub async fn add_record(record: CallRecord) -> Result<()> { CallRepository::add(record).await }
    pub async fn update_status(call_id: &str, status: CallStatus, duration: Option<u32>) -> Result<()> { CallRepository::update_status(call_id, status, duration).await }
}


